package com.classichu.jetpacksimple.widget;

import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.util.AttributeSet;

public class MarqueeTextView extends AppCompatTextView {
    private boolean mIsNeedMarquee;

    public MarqueeTextView(Context context) {
        super(context);
    }

    public MarqueeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean isFocused() {
        if (mIsNeedMarquee) {
            return true;
        }
        return super.isFocused();
    }

    public void setMarquee(boolean isNeedMarquee) {
        this.setSelected(isNeedMarquee);
        this.setSingleLine(isNeedMarquee);
        if (isNeedMarquee) {
            this.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        }
        mIsNeedMarquee = isNeedMarquee;
    }
}
